<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
//我的足迹
if($_RQ['op']=='main'){
	$gettype = $_RQ['gettype'];
	$this->session('gettype',$gettype);
	$return['params']=array();
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$gettype = $this->session('gettype');
	$gettype =$gettype?$gettype:'look';
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['title']=$_RQ['keyword'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if($gettype == 'fabu'){
		$params['mid']=$_SESSION['uid'];
		$list=pdo_getslice('jy_quan_item',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	}elseif($gettype == 'cy'){
		$params['mid']=$_SESSION['uid'];
		$params['mid']=$_SESSION['uid'];
		$jieli=pdo_getslice('jy_quan_item_jieli',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
		$list=array();
		if($jieli){
			foreach($jieli as $k=>&$item){
				$item=pdo_get('jy_quan_item',array('status'=>1,'id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
				$list[]=$item;
			}
		}
	}elseif($gettype == 'look'){
		$params['mid']=$_SESSION['uid'];
		$zujilist=pdo_getslice('jy_quan_looklog',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
		$list=array();
		if($zujilist){
			foreach($zujilist as &$item){
				$item=pdo_get('jy_quan_item',array('status'=>1,'id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
				$list[]=$item;
			}
		}
	}
	if($list){
			$sum=count($list);
			foreach($list as &$item){
				$item['content'] = json_decode($item['content'],true);
				$item['fileds'] = json_decode($item['fileds'],true);
				$item['fee']=0;
				if($item['fileds']){
					foreach($item['fileds'] as &$fv){
						foreach($fv as &$f){
							if($f['type']==18){
								$item['fee'] +=$f['data'];
							}
						}
					}
				}
				$item['fee'] =price($item['fee']);
				$item['diyform'] = json_decode($item['diyform'],true);
				$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
				$item['typetitle']=$this->itemtypes()[$item['type']];
				$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				$item['jielinum']=pdo_count('jy_quan_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
				$item['msgnumn']=pdo_count('jy_quan_item_msg',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
				$item['jieli']=pdo_getall('jy_quan_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'','createtime desc');
				
				if($item['jieli']){
					foreach($item['jieli'] as &$j){
						$j['createtime'] = date('Y-m-d H:i',$j['createtime']);
						$j['member'] = pdo_get('core_members',array('id'=>$j['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
					}
				}
				$item['msg']=pdo_getall('jy_quan_item_msg',array('checked'=>1,'uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'','createtime desc');
				if($item['msg']){
					foreach($item['msg'] as &$m){
						$m['createtime'] = date('Y-m-d H:i',$m['createtime']);
						$m['member'] = pdo_get('core_members',array('id'=>$m['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
					}
				}
				$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='copy'){
	if(!$_RQ['id']){
		exi('帖子不存在，请重新选择帖子','error');
	}
	$item=pdo_get('jy_quan_item',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	if($item['type']==2){
		exi('红包帖子，不能复制！','error');
	}
	unset($item['id']);
	$item['onlinetime']=TIMESTAMP+7*24*3600;
	$item['createtime']=TIMESTAMP;
	pdo_insert('jy_quan_item',$item);
	exi('复制成功','','main');
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('帖子不存在，请重新选择帖子','error');
	}
	pdo_delete('jy_quan_item',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('删除成功','','main');
}